﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MediaDataModel;
using System.Threading;
using MediaClient.Publish;
using System.Data.Objects;
using MediaClient.Common;
using MediaClient.QHMediaSercie;

namespace MediaClient.Shelf
{
    public partial class ShelfForm : BaseMainForm
    {
        #region private properties

        private short shelfHeight = 17;

        private short imgY = 9;

        private short lineY = 1;

        private short diskHeight = 159;

        private string currentShelfSeriesNum = "";

        private List<string> searchDiscBarcodeList = new List<string>();

        private string  searchMediaPackSql = "";

        #endregion

        public ShelfForm()
        {
            InitializeComponent();
        }

        #region Events

        private void ShelfForm_Load(object sender, EventArgs e)
        {
            InitializeForm();
        }

        private void ucShelf_Loaded()
        {
            lblShelfLoading.Visible = false;
        }

        private void lblControl_MouseMove(object sender, MouseEventArgs e)
        {
            Label currentLabel = sender as Label;
            if (currentLabel != null)
            {
                switch (currentLabel.Name)
                {
                    case "lblSearch":

                        lblSearch.Image = global::MediaClient.Properties.Resources.搜索_1;
                        break;
                }
            }
        }

        private void lblControl_Click(object sender, EventArgs e)
        {
            Label currentLabel = sender as Label;
            if (currentLabel != null)
            {
                switch (currentLabel.Name)
                {
                    case "lblSearch":
                        searchDiscBarcodeList.Clear();
                        searchMediaPackSql = "";
                        pnlShelf.Controls.Clear();
                        ucShelf.pnlShelf.Controls.Clear();
                        pnlDiscMedia.Controls.Clear();
                        lblShelfInfo.Text = "离线柜：";
                        ttDiscMedia.SetToolTip(lblShelfCapacity, lblShelfCapacity.Text);
                        ttDiscMedia.SetToolTip(lblShelfInfo, lblShelfInfo.Text);
                        lblShelfLoading.Visible = true;

                        lblShelfCapacity.Text = "容量：";
                        string discSqlStr = "";
                        string paramName = "";

                        string shelfSqlStr = GetSqlStr(out discSqlStr, out searchMediaPackSql, out paramName);
                        if (discSqlStr != "" && shelfSqlStr != "")
                        {
                            searchDiscBarcodeList.Clear();
                            using (CCTV6Entities db = new CCTV6Entities())
                            {
                                try
                                {
                                    var discBarcodes = db.GetSearchShelfDiscIDs(discSqlStr).FirstOrDefault();
                                    if (discBarcodes != null)
                                    {
                                        discBarcodes.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(discBarcode =>
                                        {
                                            if (searchDiscBarcodeList.Contains(discBarcode) == false)
                                                searchDiscBarcodeList.Add(discBarcode);
                                        });
                                    }
                                    if (searchDiscBarcodeList.Count > 0)
                                    {
                                        InitializeShelf(db.GetSearchShelves(shelfSqlStr).ToList());
                                    }

                                    else
                                        lblShelfLoading.Text = "没有相关数据。";

                                }
                                catch (Exception myE)
                                {
                                    MessageBox.Show(myE.Message);
                                }
                            }
                        }
                        break;
                }
            }
        }

        private void lblControl_MouseLeave(object sender, EventArgs e)
        {
            Label currentLabel = sender as Label;
            if (currentLabel != null)
            {
                switch (currentLabel.Name)
                {
                    case "lblSearch":
                        lblSearch.Image = global::MediaClient.Properties.Resources.搜索;
                        break;
                }
            }
        }

        private void shelfDisc_Click(object sender, EventArgs e)
        {
            Button btnDisc = sender as Button;
            if (btnDisc != null)
            {
                string[] shelfDiscInfo = btnDisc.Name.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
                if (shelfDiscInfo.Length > 5)
                {
                    try
                    {
                        DisplayDiscMedias(shelfDiscInfo[5]);
                    }
                    catch (Exception myE)
                    {
                        throw myE;
                    }
                }
            }
        }

        private void shelfDiscMedia_DoubleClick(object sender, EventArgs e)
        {
            Label lblDiscMedia = sender as Label;
            if (lblDiscMedia != null)
            {
                PublishForm oPublish = new PublishForm(long.Parse(lblDiscMedia.Name));
                oPublish.ShowDialog();
            }
        }

        private void shelf_Click(object sender, EventArgs e)
        {
            Label lblShelf = sender as Label;
            if (lblShelf != null && this.currentShelfSeriesNum != lblShelf.Name)
            {
                this.currentShelfSeriesNum = lblShelf.Name;
                InitializeShelfMediaInfo(this.currentShelfSeriesNum);
                string[] shelfInfo = lblShelf.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                lblShelfInfo.Text = "离线柜:" + shelfInfo[0];
                lblShelfCapacity.Text = "容量:" + shelfInfo[shelfInfo.Length - 1].Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[1];
                ttDiscMedia.SetToolTip(lblShelfCapacity, lblShelfCapacity.Text);
                ttDiscMedia.SetToolTip(lblShelfInfo, lblShelfInfo.Text);

                lblShelfLoading.Visible = true;
                lblShelfLoading.Focus();
                LoadShelfControl();
                #region set other sheleves image
                foreach (var shelfImgControl in pnlShelf.Controls)
                {
                    Label lblImg = shelfImgControl as Label;

                    if (lblImg.Name == ("lblImg" + this.currentShelfSeriesNum))
                        lblImg.Image = global::MediaClient.Properties.Resources.离线柜当前;
                    else if (lblImg.Name != this.currentShelfSeriesNum && lblImg.Name.Contains("lblImg") == true)
                        lblImg.Image = global::MediaClient.Properties.Resources.离线柜非当前;
                }
                #endregion
            }
        }

        private void shelf_Operate(string shelfSerialNumber, short rowIndex, short columnIndex, short columnOrderIndex, ShelfOperateType operateType, ref string discBarcode)
        {
            using (CCTV6Entities db = new CCTV6Entities())
            {
                OperateMessage oOperateMessage = null;
                ServiceProxy serviceClient = new ServiceProxy();
                oOperateMessage = serviceClient.PositionShelf(shelfSerialNumber, rowIndex, columnIndex, new ServiceMessage { IP = CommonUtility.Utility.GetLocalMachineIP(), Message = "操作货架。", UserID = (loginUser == null ? "admin" : loginUser.ID) });
                //oOperateMessage = new OperateMessage { Result = OperateResult.Success };
                if (oOperateMessage.Result == OperateResult.Success)
                {
                    DiscShelf oDiscShelf = db.DiscShelves.Where(disc => disc.ShelfSeriesNumber == shelfSerialNumber && disc.ShelfRowIndex == rowIndex && disc.ShelfColumnIndex == columnIndex && disc.ShelfColumnOrderIndex == columnOrderIndex).FirstOrDefault();
                    if (oDiscShelf != null && operateType == ShelfOperateType.CheckOut)
                    {
                        discBarcode = "";
                        db.DiscShelves.DeleteObject(oDiscShelf);
                        db.SaveChanges();
                    }
                    else if (operateType == ShelfOperateType.CheckIn)
                    {
                        DiscCheckInForm oDiscCheckin = new DiscCheckInForm();
                        oDiscCheckin.ShowDialog();
                        if (oDiscCheckin.DiscBarcode != "")
                        {
                            discBarcode = oDiscCheckin.DiscBarcode;
                            DiscShelf oDisck = new DiscShelf();
                            oDisck.DiscBarcode = oDiscCheckin.DiscBarcode;
                            oDisck.CreateDate = DateTime.Now;
                            oDisck.ShelfSeriesNumber = shelfSerialNumber;
                            oDisck.ShelfRowIndex = rowIndex;
                            oDisck.ShelfColumnIndex = columnIndex;
                            oDisck.ShelfColumnOrderIndex = columnOrderIndex;
                            db.DiscShelves.AddObject(oDisck);
                            db.SaveChanges();
                        }
                    }
                }
                else if (oOperateMessage.Result == OperateResult.Failure)
                    MessageBox.Show(oOperateMessage.Message, BaseForm.MessageBoxCaption);
                    
            }
        }

        #endregion

        #region private methods

        private void InitializeForm()
        {
            #region initialize search type

            MetaDataName allMeta = new MetaDataName();
            allMeta.ID = 1;
            allMeta.Name = "全部";
            cbSearchType.Items.Add(allMeta);
            MetaDataName movieNameMeta = new MetaDataName();
            movieNameMeta.Name = "电影名称";
            movieNameMeta.ID = 2;
            cbSearchType.Items.Add(movieNameMeta);
            using (CCTV6Entities db = new CCTV6Entities())
            {
                var metaDatas = db.MetaDataNames.Where(meta => meta.IsSearch.Value == true);
                if (metaDatas != null)
                {
                    foreach (var meta in metaDatas)
                        cbSearchType.Items.Add(meta);
                }
            }
            cbSearchType.DisplayMember = "Name";
            cbSearchType.SelectedIndex = 0;

            #endregion

            ucShelf.DiscClick += shelfDisc_Click;
            ucShelf.Loaded += ucShelf_Loaded;
            ucShelf.OperateShelf += shelf_Operate;
            InitializeShelf(null);
        }

        private void LoadShelfControl()
        {
            ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object state)
            {
                Thread.Sleep(2 * 1000);
                ucShelf.SpecialDiscList = searchDiscBarcodeList;
                ucShelf.LoadShelfInfor(this.currentShelfSeriesNum);

            }));
        }

        private void InitializeShelf(List<OfflineShelf> shelves)
        {
            try
            {

                lblShelfLoading.Text = "正在加载离线柜信息......";
                using (CCTV6Entities db = new CCTV6Entities())
                {
                    if (shelves == null)
                        shelves = db.OfflineShelves.ToList();
                    Point currentPoint = new Point();
                    for (int i = 0; i < shelves.Count(); i++)
                    {
                        string shelfSeriesNum = shelves[i].SeriesNumber;
                        if (i == 0)
                        {
                            Label lblShelfImg = new Label();
                            lblShelfImg.AutoSize = false;
                            lblShelfImg.Size = new Size(20, 16);
                            lblShelfImg.Text = "";
                            lblShelfImg.Location = new Point(8, imgY);
                            lblShelfImg.BackColor = Color.Transparent;
                            lblShelfImg.Image = global::MediaClient.Properties.Resources.离线柜当前;
                            pnlShelf.Controls.Add(lblShelfImg);
                            lblShelfImg.Name = "lblImg" + shelves[i].SeriesNumber;

                            this.currentShelfSeriesNum = shelves[i].SeriesNumber;

                            InitializeShelfMediaInfo(this.currentShelfSeriesNum);
                            LoadShelfControl();


                            string capacity = (shelves[i].RowNumber * shelves[i].ColumnNumber * shelves[i].ColumnCapacity).ToString();
                            Label lblShelf = new Label();
                            lblShelf.AutoSize = true;
                            lblShelf.Height = shelfHeight;
                            lblShelf.Location = new Point(lblShelfImg.Location.X + lblShelfImg.Width + 2, imgY);
                            lblShelf.Name = shelves[i].SeriesNumber;
                            lblShelf.Text = shelves[i].ShelfName + "  " + db.DiscShelves.Where(dis => dis.ShelfSeriesNumber == shelfSeriesNum).Count() + "/" + capacity;
                            pnlShelf.Controls.Add(lblShelf);
                            lblShelf.Click += shelf_Click;

                            lblShelfInfo.Text += shelves[i].ShelfName;
                            lblShelfCapacity.Text += capacity;
                            ttDiscMedia.SetToolTip(lblShelfCapacity, lblShelfCapacity.Text);
                            ttDiscMedia.SetToolTip(lblShelfInfo, lblShelfInfo.Text);

                            if (shelves.Count > 1)
                            {
                                Label lblSplitLine = new Label();
                                lblSplitLine.Size = new Size(1, 33);
                                lblSplitLine.Location = new Point(lblShelf.Location.X + lblShelf.Width + 30, lineY);
                                lblSplitLine.BackColor = System.Drawing.SystemColors.AppWorkspace;
                                pnlShelf.Controls.Add(lblSplitLine);
                                currentPoint = new Point(lblSplitLine.Location.X + lblSplitLine.Width + 2, lblShelf.Location.Y);
                            }
                        }
                        else
                        {
                            if ((lblMore.Location.X - currentPoint.X) > 0)
                            {
                                Label lblShelfImg = new Label();
                                lblShelfImg.AutoSize = false;
                                lblShelfImg.Location = new Point(currentPoint.X + 2, currentPoint.Y);
                                lblShelfImg.Text = "";
                                lblShelfImg.Size = new Size(20, 16);
                                lblShelfImg.BackColor = Color.Transparent;
                                lblShelfImg.Image = global::MediaClient.Properties.Resources.离线柜非当前;
                                lblShelfImg.Name = "lblImg" + shelves[i].SeriesNumber;

                                currentPoint = new Point(lblShelfImg.Location.X + lblShelfImg.Width + 2, imgY);
                                if ((lblMore.Location.X - currentPoint.X) > 0)
                                {

                                    Label lblShelf = new Label();
                                    lblShelf.AutoSize = true;
                                    lblShelf.Location = currentPoint;
                                    lblShelf.Height = shelfHeight;
                                    lblShelf.Name = shelves[i].SeriesNumber;
                                    lblShelf.Text = shelves[i].ShelfName + "  " + db.DiscShelves.Where(dis => dis.ShelfSeriesNumber == shelfSeriesNum).Count() + "/" + (shelves[i].RowNumber * shelves[i].ColumnNumber * shelves[i].ColumnCapacity).ToString(); ;
                                    currentPoint = new Point(lblShelf.Location.X + lblShelf.Width + 2, imgY);

                                    if ((lblMore.Location.X - currentPoint.X) > 0)
                                    {
                                        lblShelf.Click += shelf_Click;
                                        pnlShelf.Controls.Add(lblShelfImg);
                                        pnlShelf.Controls.Add(lblShelf);
                                        if (i < (shelves.Count - 1))
                                        {


                                            Label lblSplitLine = new Label();
                                            lblSplitLine.Size = new Size(1, 33);
                                            lblSplitLine.Location = new Point(currentPoint.X + 28, currentPoint.Y);
                                            lblSplitLine.BackColor = System.Drawing.SystemColors.AppWorkspace;
                                            currentPoint = new Point(lblSplitLine.Location.X + lblSplitLine.Width + 2, lblShelf.Location.Y);
                                            if ((lblMore.Location.X - currentPoint.X) > 0)
                                                pnlShelf.Controls.Add(lblSplitLine);
                                            else
                                            {
                                                lblMore.Visible = false;
                                                break;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        lblShelf.AutoSize = false;
                                        lblShelf.Width = lblMore.Location.X - 2 - lblShelfImg.Location.X + lblShelfImg.Width;
                                        pnlShelf.Controls.Add(lblShelf);
                                        {
                                            lblMore.Visible = false;
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    lblMore.Visible = false;
                                    break;
                                }
                            }

                        }

                    }
                }
            }
            catch (Exception myE)
            {
                throw myE;
            }
        }

        private void DisplayDiscMedias(string discBarcode)
        {
            pnlDiscMedia.Controls.Clear();
            using (CCTV6Entities db = new CCTV6Entities())
            {
                List<MediaPack> searchMediaPackList = new List<MediaPack>();
                if (this.searchMediaPackSql != "")
                    searchMediaPackList = db.GetSearchMediaPacks(this.searchMediaPackSql).ToList();
                var blueDisc = db.BlueDiscs.Where(disc => disc.Barcode == discBarcode).SingleOrDefault();
                if (blueDisc != null)
                {
                    List<MediaPack> discMediaList = blueDisc.MediaPacks.ToList();
                    for (int i = 0; i < discMediaList.Count; i++)
                    {
                        Label lblDiscMedia = new Label();
                        lblDiscMedia.Name = discMediaList[i].ID.ToString();
                        lblDiscMedia.AutoSize = false;
                        lblDiscMedia.BackColor = Color.Transparent;
                        lblDiscMedia.Image = global::MediaClient.Properties.Resources.视频;
                        lblDiscMedia.Size = new Size(107, 107);
                        lblDiscMedia.Location = new Point(66, 15 + i * diskHeight);
                        lblDiscMedia.DoubleClick += shelfDiscMedia_DoubleClick;
                        pnlDiscMedia.Controls.Add(lblDiscMedia);

                        Label lblMediaName = new Label();
                        lblMediaName.AutoSize = false;
                        lblMediaName.Size = new Size(230, 18);
                        lblMediaName.TextAlign = ContentAlignment.MiddleCenter;
                        lblMediaName.Location = new Point(2, 126 + i * diskHeight);
                        lblMediaName.Text = discMediaList[i].Name;
                        pnlDiscMedia.Controls.Add(lblMediaName);

                        if (searchMediaPackList.SingleOrDefault(media => media.ID == discMediaList[i].ID) != null)
                            lblMediaName.ForeColor = Color.OliveDrab;

                        var metaDataRecords = discMediaList[i].MetaDataRecords.OrderBy(record => record.MetaDataID);
                        StringBuilder sbToopTip = new StringBuilder();
                        foreach (var metaData in metaDataRecords)
                        {

                            sbToopTip.Append(FormatToolTripString(metaData.MetaDataName.Name + ": " + metaData.MetaDataContent,30));
                            sbToopTip.Append("\r\n");
                        }
                        if (sbToopTip.ToString() != "")
                            ttDiscMedia.SetToolTip(lblDiscMedia, sbToopTip.ToString());
                    }
                }
            }
        }

        private string GetSqlStr(out string discSqlStr, out string mediaPackSqlStr, out string paramName)
        {
            StringBuilder sbSql = new StringBuilder();
            StringBuilder sbDiscSql = new StringBuilder();
            StringBuilder sbMediaSql = new StringBuilder();
            paramName = "discIDStr";
            mediaPackSqlStr = "";
            if (txtSearch.Text.Trim() == "")
                InitializeShelf(null);
            else
            {
                sbMediaSql.Append("select distinct m.* from mediaPack m left join MetaDataRecord b  on m.id = b.MediaPackID where m.discBarcode is not null and ("); 
                sbSql.Append("select distinct o.* from offlineshelf o left join discShelf d on o.SeriesNumber = d.ShelfSeriesNumber where DiscBarcode in(");
                sbDiscSql.Append("declare @discIDStr nvarchar(max); set @discIDStr = N''; select @discIDStr = @discIDStr+ discBarcode + N';' from mediapack a left join MetaDataRecord b on a.id = b.mediaPackID where DiscBarcode is not null and ");
                string[] sqlArray = txtSearch.Text.Split(new char[] { ' ', ',', '　', '，', ';', '；' }, StringSplitOptions.RemoveEmptyEntries);
                switch (cbSearchType.SelectedIndex)
                {
                    case 0:
                        StringBuilder sbParams = new StringBuilder();
                        for (int i = 0; i < sqlArray.Length; i++)
                        {
                            if (i != (sqlArray.Length - 1))
                                sbParams.Append(sqlArray[i] + " or ");
                            else
                                sbParams.Append(sqlArray[i] + "')");
                        }
                        sbSql.Append("select Distinct DiscBarcode from mediaPack a left join MetaDataRecord b on a.id = b.mediaPackID where DiscBarcode is not null and(contains(name,'");
                        sbSql.Append(sbParams.ToString() + " or contains(MetaDataContent,'");
                        sbSql.Append(sbParams.ToString() + "))");
                        //sbSql.Append(" or DiscBarcode in(select distinct DiscBarcode from mediaPack where discBarcode is not null and id in(select mediaPackID from MetaDataRecord where contains(MetaDataContent,'");
                        

                        sbDiscSql.Append("(contains(name,'");
                        sbDiscSql.Append(sbParams.ToString());
                        sbDiscSql.Append(" or contains(MetaDataContent,'");
                        sbDiscSql.Append(sbParams.ToString() + ")");

                        sbMediaSql.Append("contains(name,'" + sbParams.ToString());
                        sbMediaSql.Append(" or contains(MetaDataContent,'" + sbParams.ToString() + ")");
                        break;
                    case 1: //电影名称
                        sbSql.Append("select distinct DiscBarcode from mediaPack where DiscBarcode is not null and contains(name,'");
                        sbDiscSql.Append("contains(name,'");
                        sbMediaSql.Append("contains(name,'");
                        for (int i = 0; i < sqlArray.Length; i++)
                        {
                            if (i != (sqlArray.Length - 1))
                            {
                                sbSql.Append(sqlArray[i] + " or ");
                                sbDiscSql.Append(sqlArray[i] + " or ");
                                sbMediaSql.Append(sqlArray[i] + " or ");
                            }
                            else
                            {
                                sbSql.Append(sqlArray[i] + "'))");
                                sbDiscSql.Append(sqlArray[i] + "')");
                                sbMediaSql.Append(sqlArray[i] + "'))");
                            }
                        }
                        break;
                    default:
                        sbSql.Append("select Distinct DiscBarcode from mediaPack a left join MetaDataRecord b on a.id = b.mediaPackID where DiscBarcode is not null and contains(MetaDataContent,'");
                        sbDiscSql.Append(" contains(MetaDataContent,'");
                        sbMediaSql.Append(" contains(MetaDataContent,'");
                        for (int i = 0; i < sqlArray.Length; i++)
                        {
                            if (i != (sqlArray.Length - 1))
                            {
                                sbSql.Append(sqlArray[i] + " or ");
                                sbDiscSql.Append(sqlArray[i] + " or ");
                                sbMediaSql.Append(sqlArray[i] + " or ");
                            }
                            else
                            {
                                sbSql.Append(sqlArray[i] + "')"); //') and metaDataID = 23)
                                sbDiscSql.Append(sqlArray[i] + "')");
                                sbMediaSql.Append(sqlArray[i] + "')");
                            }
                        }
                        sbSql.Append(" and metaDataID = " + (cbSearchType.SelectedItem as MetaDataName).ID.ToString() + ")");
                        sbDiscSql.Append(" and metaDataID = " + (cbSearchType.SelectedItem as MetaDataName).ID.ToString());
                        sbMediaSql.Append(" and metaDataID = " + (cbSearchType.SelectedItem as MetaDataName).ID.ToString() + ")");
                        break;
                }
            }
            sbDiscSql.Append(" select @discIDStr;");
            discSqlStr = sbDiscSql.ToString();
            mediaPackSqlStr = sbMediaSql.ToString();
            return sbSql.ToString();
        }

        private void InitializeShelfMediaInfo(string shelfSeriesNum)
        {
            pnlDiscMedia.Controls.Clear();
            using (CCTV6Entities db = new CCTV6Entities())
            {
                var currentShelf = db.OfflineShelves.Where(shelf => shelf.SeriesNumber == shelfSeriesNum).SingleOrDefault();
                if (currentShelf != null)
                {
                    int discCount = currentShelf.DiscShelves.Count;
                    int mediaCount = 0;
                    foreach (var discShelf in currentShelf.DiscShelves)
                    {
                        if (discShelf.BlueDisc != null && discShelf.BlueDisc.MediaPacks != null)
                            mediaCount += discShelf.BlueDisc.MediaPacks.Count;
                    }
                    //lblDiscCount.Text = "离线光盘 " + discCount.ToString() + " 张";
                    //lblMediaPackCount.Text = mediaCount.ToString() + " 部电影";

                    Label lblImage = new Label();
                    lblImage.Size = new Size(107, 107);
                    lblImage.Location = new Point(68, 50);
                    lblImage.BackColor = Color.Transparent;
                    lblImage.Image = global::MediaClient.Properties.Resources.盘片当前;
                    pnlDiscMedia.Controls.Add(lblImage);

                    Label lblDiscCount = new Label();
                    lblDiscCount.TextAlign = ContentAlignment.MiddleCenter;
                    lblDiscCount.Location = new Point(6, 166);
                    lblDiscCount.Size = new Size(226, 21);
                    lblDiscCount.Text = "离线光盘 " + discCount.ToString() + " 张";
                    pnlDiscMedia.Controls.Add(lblDiscCount);

                    Label lblMediaCount = new Label();
                    lblMediaCount.TextAlign = ContentAlignment.MiddleCenter;
                    lblMediaCount.Location = new Point(6, 186);
                    lblMediaCount.Size = new Size(226, 21);
                    lblMediaCount.Text = mediaCount.ToString() + " 部电影";
                    pnlDiscMedia.Controls.Add(lblMediaCount);
                }
            }
        }

        private string FormatToolTripString(string resource, short countPRow)
        {
            StringBuilder sbTemp = new StringBuilder();
            int i = 0;

            while (resource.Length > countPRow)
            {
                i++;
                sbTemp.Append(resource.Substring(0, countPRow) + "\r\n");
                resource = resource.Substring(countPRow);
            }
            if (resource.Length > 0)
                sbTemp.Append(resource);
            return sbTemp.ToString();
            //return resource;
        }

        #endregion

        
    }
}
